package com.lanju.controller;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.apache.http.client.ClientProtocolException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanju.common.Contants;
import com.lanju.util.WeiXinUtil;
/**
 * 客服接口
 * @author Administrator
 *
 */
@Controller
@RequestMapping("cusService")
public class CusServiceController {
	
	@RequestMapping("getCusList")
	@ResponseBody
	public Map<String,Object> getCusList(HttpServletRequest request) throws ClientProtocolException{
		String url="https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token="+Contants.ACCESS_TOKEN;
		try {
			JSONObject obj=WeiXinUtil.doGetStr(url);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@RequestMapping("sendMessage")
	@ResponseBody
	public Map<String,Object> sendMessage(HttpServletRequest request) throws ClientProtocolException{
		String url="https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="+Contants.ACCESS_TOKEN;
		String content="{ \"touser\":\"OPENID\",\"msgtype\":\"text\", \"text\":{\"content\":\"Hello World\" }}";
		try {
			JSONObject obj=WeiXinUtil.doPostStr(url, content);
			System.out.println(obj);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@RequestMapping("addCusService")
	@ResponseBody
	public Map<String,Object> addCusService(HttpServletRequest request) throws ClientProtocolException{
		String url="https://api.weixin.qq.com/customservice/kfaccount/add?access_token="+Contants.ACCESS_TOKEN;
		String content="{\"kf_account\" : \"owTEZwpwaKzHlUf_s7CM6hJodA9o@test\",\"nickname\" : \"客服1\" }";
		try {
			JSONObject obj=WeiXinUtil.doPostStr(url, content);
			System.out.println(obj);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}
